!> author: 左志华
!> date: 2022-07-16
!>
module test_load_toml_m

    use testdrive, only: new_unittest, unittest_type, error_type, check
    use sph_kinds, only: rk
    use seakeeping_filesystem, only: is_exist
    use sph_project_type, only: project_t
    use sph_navier_stokes_solver, only: dt
    use sph_load_toml
    implicit none
    private

    public :: collect_load_toml

contains

    !> Collect all exported unit tests
    subroutine collect_load_toml(testsuite)
        !> Collection of tests
        type(unittest_type), allocatable, intent(out) :: testsuite(:)

        allocate (testsuite, source=[ &
                  new_unittest("FUNC: parse_project_toml", test_parse_project_toml) &
                  ])

    end subroutine collect_load_toml

    impure subroutine test_parse_project_toml(error)
        type(error_type), allocatable, intent(out) :: error
        type(project_t) :: project

        if (is_exist("test/for-test/sph-config.nml")) then
            call parse_project_toml(project, "test/for-test")
            call check(error, project%path, "test/for-test")
        else ! 用于 meson test
            call parse_project_toml(project, "../test/for-test")
            call check(error, project%path, "../test/for-test")
        end if
        if (allocated(error)) return

        call check(error, project%name, "test-demo")
        if (allocated(error)) return

        call check(error, dt, 1.0_rk)

    end subroutine test_parse_project_toml

end module test_load_toml_m
